<template>
  <div class="home">

      <div @click="WebSocketTest()">djfke</div>
  </div>
</template>
<script>
export default {
  name: "home",
  components: {
  },
  data() {
    return {
      ws: ""
    };
  },
  created() {

  },
  mounted() {
    let _this = this;
    // _this.tax();
    _this.websok();
  },
  methods: {
    websok() {
      let _this = this;
      let url = "ws://10.1.2.207:8080/websocket/" + "210";
      if ("WebSocket" in window || WebSocket in window) {
        _this.ws = new WebSocket(url);

        _this.ws.onmessage = function(evt) {
          var received_msg = evt.data;
          console.log(received_msg);
        };
        _this.ws.onclose = function() {
          alert("连接已关闭...");
        };
      }
    },
    WebSocketTest: function() {
      let _this = this;
      if (_this.ws.readyState == WebSocket.OPEN) {
        _this.ws.send("发送数据");
      }
    },
  }
};
</script>
<style lang='less'>
</style>